#!/bin/bash
 if [ -f /etc/docker/daemon.json ]; then
    rm /etc/docker/daemon.json
 fi
 PROXY=$1
 NO_PROXY="hub.cangling.cn,localhost,docker.m.daocloud.io,127.0.0.1,10.10.10.0/24,10.241.0.0/16,192.168.1.0/24,10.96.0.0/12"
cat <<EOF > /etc/docker/daemon.json
{
  "registry-mirrors": ["https://docker.m.daocloud.io"],
  "proxies": {
    "http-proxy": "$PROXY",
    "https-proxy": "$PROXY",
    "no-proxy": "${NO_PROXY}"
  }
}
EOF


if [ -f /etc/systemd/system/docker.service.d/http-proxy.conf ]; then
    rm /etc/systemd/system/docker.service.d/http-proxy.conf
fi
cat <<EOF | tee /etc/systemd/system/docker.service.d/http-proxy.conf
[Service]
Environment="HTTP_PROXY=$PROXY"
Environment="HTTPS_PROXY=$PROXY"
Environment="NO_PROXY=${NO_PROXY}"
EOF

systemctl daemon-reload
systemctl restart docker
